package dilmaj.client;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;

import dilmaj.shared.StarEntryVO;

public class StarButtonPanel extends HorizontalPanel {
	StarEntryVO dataVO;
	Button button=new Button();
	CheckBox check=new CheckBox();
	TextArea description=new TextArea();
	Label userLabel=new Label();
	boolean isPopup;
	StarPanel child=null;
	
	public void setChildPanel(StarPanel starPanel) {
		child=starPanel;
	}
	
	public StarPanel getChildPanel() {
		return child;
	}
	
	public StarButtonPanel(StarEntryVO baseVO, StarEntryVO dataVO, boolean isPopup) {
		super();
		if (dataVO.getCaption()==null) {
			dataVO.setCaption("");
		}
		button.setText(dataVO.getCaption());
		this.dataVO=dataVO;
		
		//dataVO.setButtonPanel(this);
		
		button.setTitle(dataVO.getTitle());
		button.addClickHandler(new StarButtonHandler(this, dataVO));
		
		this.isPopup=isPopup;
		
		check.setEnabled(isPopup);
		check.addClickHandler(new CheckHandler(baseVO, this));
		if (baseVO!=null)
			if (baseVO.has(dataVO))
				check.setValue(true);
		add(check);
		add(button);
		String title=dataVO.getTitle();
		if (title.compareToIgnoreCase("comment")==0 || title.compareToIgnoreCase("usecase")==0) {
			add(description);
			description.setText(dataVO.getDescription());
			description.setReadOnly(true);
			check.setVisible(false);
			check.setValue(true);
			if (baseVO!=null)
				if (!baseVO.has(dataVO))
					baseVO.addAttachment(dataVO);
		}
		
		String username=dataVO.getUsername();
		if (username!=null)
			if (username.compareTo("")!=0) {
				userLabel.setText(username);
				add(userLabel);
			}
	}
	
	public StarEntryVO getData() {
		return dataVO;
	}
	
	public boolean isChecked() {
		return check.getValue();
	}
	
	public Button getButton() {
		return button;
	}
}
